import { commonOption } from 'api/config'
import axios from 'axios'

export function modeGet(param) {
  if (param.indexOf('orgId') < 0) {
    if (param.indexOf('?') < 0) {
      param = param + '?orgId=' + sessionStorage.getItem('siteId')
    } else {
      param = param + '&orgId=' + sessionStorage.getItem('siteId')
    }
  }
  const url = commonOption.host + param
  const params = Object.assign({}, param)
  return axios.get(url, {
    params: params
  })
}

export function modeGet2(param) {
  if (param.indexOf('orgId') < 0) {
    if (param.indexOf('?') < 0) {
      param = param + '?orgId=' + sessionStorage.getItem('siteId')
    } else {
      param = param + '&orgId=' + sessionStorage.getItem('siteId')
    }
  }
  const url = param
  const params = Object.assign({}, param)
  return axios.get(url, {
    params: params
  })
}

export function modePost (path, param) {
  const url = commonOption.host + path
  let formData = new FormData()
  for (let key in param) {
    formData.append(key, param[key])
  }
  formData.set('orgId', sessionStorage.getItem('siteId'))
  return axios.post(url, formData)
}
export function modePost2 (path, param) {
  const url = path
  let formData = new FormData()
  for (let key in param) {
    formData.append(key, param[key])
  }
  formData.set('orgId', sessionStorage.getItem('siteId'))
  return axios.post(url, formData)
}
